﻿using ChuanYe.Core.Utils;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace ChuanYe.WorkLogManagement.EF.SqlServer
{
    public class WorkLogContext : DbContext
    {
        public WorkLogContext()
        {

        }
        public WorkLogContext(DbContextOptions options) : base(options)
        {
           
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                var connectionString = AppSetting.GetConfig("WorkLogManagement:ConnectionString");
                optionsBuilder.UseSqlServer(connectionString);
            }
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<UserInfo>().HasIndex(h => h.AccountName) .IsUnique();
        }

        public DbSet<UserInfo> UserInfo { get; set; }
        public DbSet<DepartmentInfo> DepartmentInfo { get; set; }

        public DbSet<UserPowerInfo> UserPowerInfo { get; set; }

        public DbSet<WorkInfo> WorkInfo { get; set; }

        public DbSet<PositionInfo> PositionInfo { get; set; }

    }
}
